<template>
  <el-form-item v-show="isShow" :label="i18nt('designer.setting.userId')">
    <el-input-number
      v-model="userId"
      class="hide-spin-button"
      style="width: 100%"
      :min="20001"
      :step="1"
      disabled
    ></el-input-number>
  </el-form-item>
</template>

<script>
export default {
  name: 'UserIdEditor',
  props: {
    designer: Object,
    selectedWidget: Object,
    optionModel: Object
  },
  computed: {
    userId: {
      get() {
        return this.optionModel['userId']
      },

      set(newValue) {
        //if ((!newValue && (newValue !== 0)) || isNaN(newValue)) {
        if (newValue === undefined || newValue === null || isNaN(newValue)) {
          this.optionModel.userId = null
        } else {
          this.optionModel.userId = Number(newValue)
        }
      }
    },
    isShow() {
      // Hide when:
      // 1. Component is 'number' and isInput is 0
      // 2. Component is 'text' and isInput is 0
      if (this.selectedWidget) {
        if (
          (this.selectedWidget.type === 'number' && 
           this.selectedWidget.options.isInput === 0) ||
          (this.selectedWidget.type === 'text' && 
           this.selectedWidget.options.isInput === 0)
        ) {
          return false
        }
      }
      return true
    }
  }
}
</script>

<style scoped></style>
